package com.gxa.admin.utils;

import com.gxa.core.result.Result;
import com.gxa.core.result.ResultUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import java.util.List;

/**
 */
public class WebUtils {

    /**
     * 处理校验失败的信息
     * @param bindingResult
     * @return
     */
    public static Result getErrors(BindingResult bindingResult) {
        List<ObjectError> errors = bindingResult.getAllErrors();

        StringBuilder sb=new StringBuilder();

        for(ObjectError objectError:errors){
            String message = objectError.getDefaultMessage();
            sb.append(message+",");
        }

        return ResultUtils.buildFail(500003,sb.toString().substring(0,sb.toString().length()-1));
    }

}
